package network;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;

/**
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/12/9 14:25
 */
public class IpDemo {
    public static void main(String[] args) throws Exception {
        // 获取本地ip
        InetAddress host = InetAddress.getLocalHost();
        System.out.println(host.getHostAddress());
        System.out.println(host.getHostName());
        ping();
    }

    private static void ping() throws IOException {
        Process process = Runtime.getRuntime().exec("ping 10.0.20.249");
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK"));
        String s;
        while ((s = reader.readLine()) != null) {
            System.out.println(s);
        }
    }
}
